﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SoundcloudSharp;
using SoundcloudSharp.Model;

namespace SoundcloudSharp.Endpoints.Users {
    public class Unauthenticated : SoundcloudAPI
    {

        public Unauthenticated(SoundcloudConfig config) : base(config, "users") { }

        public User Get(int userId) {
            return (User)Mapper.Map<User>(GetJson(userId));
        }

        public string GetJson(int userId) {
            string uri = string.Format(base.Uri + "/{0}.json?consumer_key={1}", userId, SoundcloudConfig.ClientId);
            return HttpClientOld.GET(uri);
        }

        public List<Track> GetTracks(int userId)
        {
            return (List<Track>)Mapper.Map<List<Track>>(GetTracksJson(userId));
        }

        public string GetTracksJson(int userId)
        {
            string uri = string.Format(base.Uri + "/{0}/tracks.json?consumer_key={1}", userId, SoundcloudConfig.ClientId);
            return HttpClientOld.GET(uri);
        }

        public List<User> Search(string searchTerm, int? count)
        {
            return (List<User>)Mapper.Map<List<User>>(SearchJson(searchTerm, count));
        }

        public string SearchJson(string searchTerm, int? count)
        {
            string uri = string.Format(base.Uri + ".json?q={0}&consumer_key={1}", searchTerm, SoundcloudConfig.ClientId);

            if (count != null) uri += "&limit=" + count;

            return HttpClientOld.GET(uri);
        }
    }
}
